<script type="text/javascript" src="<?php echo TEMPLATES_PATH;?>/js/view.js"></script>
<script type="text/javascript" src="<?php echo TEMPLATES_PATH;?>/js/newView.js"></script>

<header class="layout head padding-small">
    <a href="javascript:back(true);" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">礼品详情</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>

<!--商品大图轮播S-->
<div class="goodsHead layout bg-white margin-bottom">
	<div class="goodsBanner">
		<div class="banner">
			<ul class="carousel">
				<li class="item"><a href=""><img src="<?php echo SiteUrl.DS.$output['prodinfo']['pgoods_image'];?>" alt="" width="300" height="300"></a></li>
			</ul>
		</div>
	</div>
</div>
<!--商品大图轮播E-->
<!--商品买卖信息S-->
<div class="goods-sales layout bg-white padding height  margin-bottom">
	<h5 class="goodsName "><a href="javascript:;"><?php echo $output['prodinfo']['pgoods_name']; ?></a></h5>
	<div class="">兑换积分：<i class="text-big text-ef7f7e"><strong><?php echo $output['prodinfo']['pgoods_points']; ?></i></div>
	<div class="">价格：<i class="goodsOldPrice text-ef7f7e"><?php if($_SESSION['is_login'] != 1){?><a url="index.php?act=login" style="font-size:14px; color:#FFF" onClick="pclicked(this);">登录后显示</a><?php }else{?>&yen;<?php echo $output['prodinfo']['pgoods_price']; ?><?php }?></i></div>
</div>
<!--商品买卖信息E-->
<!--购买规格及数量S-->
<div class="layout bg-white padding  margin-bottom">
	<div class="height">我的积分：<span class=""><?php echo $output['member_info']['member_points']; ?></span></div>
	<div class="height">礼品编号：<span class=""><?php echo $output['prodinfo']['pgoods_serial']; ?></span></div>
	<!-- 兑换时间 -->
	<?php if ($output['prodinfo']['pgoods_islimittime'] == 1){ ?>
		<h6><?php echo $lang['pointprod_info_goods_limittime'].$lang['nc_colon']; ?>
			<?php if ($output['prodinfo']['pgoods_starttime'] && $output['prodinfo']['pgoods_endtime']){
				echo @date('Y-m-d H:i:s',$output['prodinfo']['pgoods_starttime']).'&nbsp;'.$lang['pointprod_info_goods_limittime_to'].'&nbsp;'.@date('Y-m-d H:i:s',$output['prodinfo']['pgoods_endtime']);
			}?>
		</h6>
		<?php if ($output['prodinfo']['ex_state'] == 'going'){?>
			<h6><?php echo $lang['pointprod_info_goods_lasttime']; ?>&nbsp;&nbsp;<i id="dhpd"><?php echo $output['prodinfo']['timediff']['diff_day']; ?></i> <?php echo $lang['pointprod_info_goods_lasttime_day']; ?> <i id="dhph"><?php echo $output['prodinfo']['timediff']['diff_hour']; ?></i> <?php echo $lang['pointprod_info_goods_lasttime_hour']; ?> <i id="dhpm"><?php echo $output['prodinfo']['timediff']['diff_mins']; ?></i> <?php echo $lang['pointprod_info_goods_lasttime_mins']; ?> <i id="dhps"><?php echo $output['prodinfo']['timediff']['diff_secs']; ?></i> <?php echo $lang['pointprod_info_goods_lasttime_secs']; ?></h6>
		<?php }?>
	<?php } ?>

	<?php if ($output['prodinfo']['ex_state'] == 'going'){?>
	<div class="height">剩余数量：<span class="storage"><?php echo $output['prodinfo']['pgoods_storage']; ?></span>
		<input type="hidden" id="storagenum" value="<?php echo $output['prodinfo']['pgoods_storage']; ?>"/>
	</div>
	<?php }?>


	<?php if ($output['prodinfo']['ex_state'] == 'willbe'){ ?>
	<a href="javascript:;" class="inlineBlock bg-red radius-big padding height text-white "><i class="icon-gift text-big padding-right"></i><?php echo $lang['pointprod_willbe']; ?></a>
	<?php }elseif ($output['prodinfo']['ex_state'] == 'end') {?>
		<a href="javascript:;" class="inlineBlock bg-red radius-big padding height text-white "><i class="icon-gift text-big padding-right"></i><?php echo $lang['pointprod_exchange_end']; ?></a>
	<?php }else{?>
		<div class="clearfix padding-bottom">
			<span class="float-left height"><?php echo $lang['pointprod_info_goods_exchangenum'].$lang['nc_colon']; ?></span>
			<div class="float-left radius text-center border border-ef7f7e goods-num">
				<span class=" bg-ef7f7e inlineBlock text-white numDel">-</span>
				<span class="numWrite inlineBlock" ><input name="exnum" id="exnum" type="text" placeholder="1" class="text-center border-none" value="1"></span>
				<span class="text-white inlineBlock bg-red numAdd">+</span>
			</div>
		</div>
		<a href="javascript:add_to_cart();" class="inlineBlock bg-red radius-big padding height text-white "><i class="icon-gift text-big padding-right"></i><?php echo $lang['pointprod_exchange']; ?></a>
		<?php if ($output['prodinfo']['pgoods_islimit'] == 1){?>
			<h5><?php echo $lang['pointprod_info_goods_limitnum_tip1']; ?><?php echo $output['prodinfo']['pgoods_limitnum']; ?><?php echo $lang['pointprod_pointprod_unit']; ?></h5>
			<input type="hidden" id="limitnum" value="<?php echo $output['prodinfo']['pgoods_limitnum']; ?>"/>
		<?php }else {?>
			<input type="hidden" id="limitnum" value=""/>
		<?php } ?>
	<?php }?>

</div>
<!--购买规格及数量E-->
<!--图文介绍S-->
<div class="layout bg-yellow text-center">
	<span class="goodsIntroduce-btn text-white height-large border-left-right border-yellow"><?php echo $lang['pointprod_info_goods_description']; ?></span>
</div>
<div class=" bg-white layout pgoods_body">
	<?php echo $output['prodinfo']['pgoods_body']; ?>
</div>
<!--图文介绍E-->


<script type="text/javascript">
var goods_storage = parseInt("<?php echo $output['prodinfo']['pgoods_storage']; ?>");
function GetRTime2() //积分礼品兑换倒计时
{
	var rtimer=null;
	var startTime = new Date();
	var EndTime = <?php echo intval($output['prodinfo']['pgoods_endtime'])*1000;?>;
	var NowTime = new Date();
	var nMS =EndTime - NowTime.getTime();
	if(nMS>0)
	{
		var nD=Math.floor(nMS/(1000*60*60*24));
		var nH=Math.floor(nMS/(1000*60*60)) % 24;
		var nM=Math.floor(nMS/(1000*60)) % 60;
		var nS=Math.floor(nMS/1000) % 60;
		document.getElementById("dhpd").innerHTML=pendingzero(nD);
		document.getElementById("dhph").innerHTML=pendingzero(nH);
		document.getElementById("dhpm").innerHTML=pendingzero(nM);
		document.getElementById("dhps").innerHTML=pendingzero(nS);
		if(nS==0&&nH==0&&nM==0)
		{
			// document.getElementById("returntime").style.display='none';
			clearTimeout(rtimer2);
			window.location.href=window.location.href;
			return;
		}
		rtimer2=setTimeout("GetRTime2()",1000);
	}
}
GetRTime2();
function pendingzero(str)
{
	var result=str+"";
	if(str<10)
	{
		result="0"+str;
	}
	return result;
}
//加入进货车
function add_to_cart()
{
	var storagenum = parseInt($("#storagenum").val());//库存数量
	var limitnum = parseInt($("#limitnum").val());//限制兑换数量
	var quantity = parseInt($("#exnum").val());//兑换数量	
	//验证数量是否合法
	var checkresult = true;
	var msg = '';
	if(!quantity >=1 ){//如果兑换数量小于1则重新设置兑换数量为1
		quantity = 1;
	}
	if(limitnum > 0 && quantity > limitnum){
		checkresult = false;
		msg = '<?php echo $lang['pointprod_info_goods_exnummaxlimit_error']; ?>';
	}
	if(storagenum > 0 && quantity > storagenum){
		checkresult = false;
		msg = '<?php echo $lang['pointprod_info_goods_exnummaxlast_error']; ?>';
	}

	if(checkresult == false){
		alert(msg);
		return false;
	}else{
		pclicked('index.php?'+"act=pointcart&op=add&pgid=<?php echo $output['prodinfo']['pgoods_id']; ?>&quantity="+quantity);
		//window.location.href = 'index.php?act=pointcart&op=add&pgid=<?php echo $output['prodinfo']['pgoods_id']; ?>&quantity='+quantity;
	}
}

$('.numAdd').click(function(){
	add();
});

$('.numDel').click(function(){
	reduce();
});


function reduce() {
	var a = parseInt($("#exnum").val(), 10);
	if (a <= 1) {
		$("#exnum").val(1)
	} else {
		a--;
		$("#exnum").val(a)
	}
}
function add() {
	var a = parseInt($("#exnum").val(), 10);
	max = parseInt($('.storage').text());
	if(a < max){
		$('#exnum').val(a+1);
	}else{
		iconShow('亲，没有更多宝贝了，赶紧下手吧~！');  //此处无法弹框
	}
}
</script> 

